// Town 11: River Bend
begintownscript;

variables;

short choice,dummy,i;
string dlgstr;

body;

beginstate INIT_STATE;
	enable_add_chars(1);
	turn_off_training(1);
	
	change_blocked(3,8,1);
	change_blocked(3,9,1);
	change_blocked(2,8,1);
	change_blocked(2,9,1);
	change_blocked(1,8,1);
	change_blocked(1,9,1);
	
	change_blocked(5,5,1);
	change_blocked(6,5,1);
	change_blocked(5,4,1);
	change_blocked(6,4,1);
	change_blocked(5,3,1);
	change_blocked(6,3,1);
	
	add_char_to_group(6,1);
	add_char_to_group(7,1);
	add_char_to_group(8,1);
	add_char_to_group(9,1);
	add_char_to_group(10,1);
	add_char_to_group(11,1);
	add_char_to_group(12,1);
	
	set_level(10,45);
	set_level(17,45);
	set_level(19,45);
	set_level(24,45);
	
	force_instant_terrain_redraw();
	
	set_flag(11,0,1);
	
	if (get_flag(11,7) == 0)
		{message_dialog("From here, you can see that you are in the middle of a large, open area filled with ancient skeletons. The river cuts west, and there is a large pack of dark wyrms in between you and the bend in the river.","The footing here is rather unstable. You won't be able to come back this way in a hurry.");
		set_flag(11,7,1);
		}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
if (is_combat())
	{message_dialog("The ground here is too unstable to traverse during combat. You can't go this way.","");
	block_entry(1);
	end();
	}

if ((get_flag(250,4) == 1) && (has_item(451) == 0))
	{message_dialog("You can't just leave Phaedra behind. You must take her with you to the guardpost immediately or she will die.","");
	block_entry(1);
	end();
	}
	
	reset_dialog();
	add_dialog_str(0,"There is a small, narrow tunnel here. Do you wish to continue?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Continue north.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else
		{set_flag(11,10,1);
		move_to_new_town(10,30,41);
		}
break;

beginstate 11;
if (get_flag(11,6) != 0)
	end();
	
	message_dialog("You find here a very old body clearly of humanoid reptilian origin. It must have been a slith. But oddly, it is wearing a vahnatai cloak! Further evidence of contact between the ancient sliths and the vahnatai, you suppose.","It is also wearing a shiny charm.");
	set_flag(11,6,1);
break;

beginstate 12;
	reset_dialog();
	add_dialog_str(0,"The river is fairly shallow, though wide. You think you could wade across. What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Attempt to wade it.");
	choice = run_dialog(1);
	if (choice == 1)
		end();
	if (choice == 2)
		{block_entry(1);
		i = 0;
		while (char_ok(i) == 0)
			{i = i + 1; }
		relocate_character(0,6,41);
		relocate_character(1,6,42);
		relocate_character(2,6,43);
		relocate_character(3,6,44);
		relocate_character(4,6,45);
		set_character_facing(0,0);
		set_character_facing(1,0);
		set_character_facing(2,0);
		set_character_facing(3,0);
		set_character_facing(4,0);
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		force_instant_terrain_redraw();
		pause(1 * get_flag(250,8));
		
		march_party(6,40);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,39);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,38);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,37);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,36);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,35);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(5,35);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(4,35);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(4,34);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(4,33);
		force_instant_terrain_redraw();
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		message_dialog("You make it across safely!","");
		}
break;

beginstate 13;
	if (character_in_party(1410) > 0) // Ithik
		{if (get_flag(250,4) != 1)
			{message_dialog("When you reach the wading point in the river, Ithik stops. _We cannot go farther from Bahssikava. We must fight Nolagh-Khar. If you need a place to rest, I know of one nearby. It is just north of here._","");
			block_entry(1);
			end();
			}
		else
			{message_dialog("When you reach the wading point in the river, Ithik stops. _I cannot go farther from Bahssikava. You must return Phaedra to the guardpost, but I cannot come with you. I will wait here for your return._","");
			set_flag(11,12,remove_char_from_party(1410));
			choice = 2;
			}
		}
	else
		{reset_dialog();	
		add_dialog_str(0,"The river is fairly shallow, though wide. You think you could wade across. What do you do?",0);
		add_dialog_choice(0,"Leave.");
		add_dialog_choice(1,"Attempt to wade it.");
		choice = run_dialog(1);
		}
	if (choice == 1)
		end();
	if (choice == 2)
		{block_entry(1);
		i = 0;
		while (char_ok(i) == 0)
			{i = i + 1; }
		relocate_character(0,6,35);
		relocate_character(1,6,34);
		relocate_character(2,6,33);
		relocate_character(3,5,33);
		relocate_character(4,4,33);
		set_character_facing(0,4);
		set_character_facing(1,4);
		set_character_facing(2,4);
		set_character_facing(3,4);
		set_character_facing(4,4);
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		force_instant_terrain_redraw();
		pause(1 * get_flag(250,8));
		
		march_party(6,36);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,37);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,38);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,39);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,40);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,41);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,42);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,43);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,44);
		force_instant_terrain_redraw();
		if ((char_on_loc(6,40) >= 0) || (char_on_loc(6,36) >= 0))
			play_sound(85);
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		march_party(6,45);
		force_instant_terrain_redraw();
		force_view_center(char_loc_x(i),char_loc_y(i));
		pause(1 * get_flag(250,8));
		
		message_dialog("You make it across safely!","");
		}
break;

beginstate 14;
if (is_combat())
	{block_entry(1);
	message_dialog("The footing here is too unstable to go through in combat.",""); }
break;

beginstate 15;
if (get_flag(11,8) != 0)
	end();
	
	message_dialog("You can hear the hisses of several more dark wyrms back this way. This must be their home.","Dark wyrms like to collect shiny items and store them in their nests. This means they occasionally have valuable items. You keep alert for treasure.");
	set_flag(11,8,1);
break;

beginstate 16;
if ((char_ok(26)) || (char_ok(27)) || (char_ok(28)))
	{block_entry(1);
	message_dialog("The doomguards are still behind you. This passageway is cramped and difficult to walk through, and if you were to attempt it with the doomguards still alive, they would catch up to you and tear to you pieces.","You can't pass.");
	end(); }

if (get_flag(250,4) == 1) // Phaedra dead
	{add_dialog_str(0,"There is a small, rubble-filled slope down to the west here. However, you can't go this way: Phaedra needs you to bring her back to the guardpost.",0);
	dummy = run_dialog(1);
	block_entry(1);
	end();
	}

	reset_dialog();
	add_dialog_str(0,"There is a small, rubble-filled slope down to the west here. Do you wish to walk down it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Walk down the passage.");
	choice = run_dialog(1);
	if (choice == 2)
		move_to_new_town(12,39,28);
break;

beginstate 17;
if (get_flag(11,9) != 0)
	end();
	
	message_dialog("There is a small cave here where a distinctly reptilian humanoid -- presumably a slith -- died. There is almost no moisture here whatsoever, so the body is relatively well-preserved.","Still, it must be at least several decades old.");
	set_flag(11,9,1);
break;

beginstate 18;
if (get_flag(11,10) != 0)
	end();
	
	message_dialog("This slith corpse is ancient. Almost everything has rotted away. However, you notice something strange: it is carrying not a traditional two-tined slith spear, but a sword!","The sword is shattered, so you can't tell much about it, but the pommel is very clearly that of a sword and not any other weapon. You make a mental note of this.");
	set_flag(11,10,1);
break;

beginstate 19;
if ((char_ok(26)) || (char_ok(27)) || (char_ok(28)))
	{block_entry(1);
	message_dialog("The ground here is filled with rubble, and the footing is unsteady. With the doomguards still behind you, to try to navigate this passage would be suicide.","You can't pass.");
	end(); }
	
if (get_flag(250,4) == 1) // Phaedra dead
	{add_dialog_str(0,"There is a small, rubble-filled passageway to the north here. However, you can't go this way: Phaedra needs you to bring her back to the guardpost.",0);
	dummy = run_dialog(1);
	block_entry(1);
	end();
	}

	reset_dialog();
	add_dialog_str(0,"There is a small, rubble-filled passageway to the north here. Do you wish to walk down it?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Walk down the passage.");
	choice = run_dialog(1);
	if (choice == 1)
		block_entry(1);
	if (choice == 2)
		{set_flag(11,13,1);
		move_to_new_town(10,6,38); }
break;

beginstate 20;
if (get_flag(11,14) != 0)
	end();
	
	set_flag(11,14,1);
	message_dialog("The river grows wide and shallow to the west of here. You think you might be able to wade it.","");
break;

beginstate 21;
if (get_flag(11,12) != 1)
	end();
	
	message_dialog("Ithik is waiting here for you. He rejoins the party.","");
	activate_hidden_group(1);
	set_flag(11,12,add_char_to_party(30) - 1);
break;

beginstate 22;
if (get_flag(11,15) != 0)
	end();
	
	set_flag(11,15,1);
	message_dialog("Down this way, you hear the sound of clanking. From your experience, you know what it means: doomguards.","Doomguards are not natural creatures; they do not breed. They are made by someone. That means that someone with great magical power was here at some point. However, once made, doomguards persist for a long time, so whoever it was may be long gone now.");
break;